package interfaces.admin;
/**
 * @author  Jennifer Henry
 */

import interfaces.FrameAccueil;

import java.awt.event.*;
import java.util.Stack;

import javax.swing.*;

import donnees.Donnees;

public class FrameAdmin extends javax.swing.JFrame {
    
	protected FrameAccueil frame;
	
	protected ModelAdmin model;

	protected PanelAdmin panelCourant;
	protected Stack<PanelAdmin> panelsPrecedents;
	
	protected PanelAdminAccueil accueil;
	protected PanelAdminModifRoute modifRoute;
	protected PanelAdminModifTroncon modifTroncon;
	protected PanelAdminModifVille modifVille;
	protected PanelAdminRechAvRoute rechAvRoute;
	protected PanelAdminRechAvTroncon rechAvTroncon;
	protected PanelAdminRechAvVille rechAvVille;
	protected PanelAdminRechRoute rechRoute;
	protected PanelAdminRechTroncon rechTrocon;
	protected PanelAdminRechVille rechVille;

    public FrameAdmin(FrameAccueil _frame, Donnees d) {

        model = new ModelAdmin(d);
    	frame = _frame;

    	accueil = new PanelAdminAccueil(this);
    	modifRoute = new PanelAdminModifRoute(this);
    	modifTroncon = new PanelAdminModifTroncon(this);
    	modifVille = new PanelAdminModifVille(this);
    	rechAvRoute = new PanelAdminRechAvRoute(this);
    	rechAvTroncon = new PanelAdminRechAvTroncon(this);
    	rechAvVille = new PanelAdminRechAvVille(this);
    	rechRoute = new PanelAdminRechRoute(this);
    	rechTrocon = new PanelAdminRechTroncon(this);
    	rechVille = new PanelAdminRechVille(this);
    	
    	panelsPrecedents = new Stack<PanelAdmin>();
    	
        initComponents();
    }
    private void initComponents() {
        addWindowListener(new WindowAdapter () {
			public void windowClosed(WindowEvent arg0) {
				frame.setFrameAdminOpen(false);
			}
        });
        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
        pack();
    }
    
    public void open () {
    	if (!isVisible()) {
    		setVisible(true);
        	setPanel(accueil);
    	}
    	pack();
    	toFront();
    }

    public ModelAdmin getModel () {
    	return model;
    }

    public void afficherCreationRoute () {
    	modifRoute.setCreation(true);
    	setNouveauPanel(modifRoute);
    }
    public void afficherCreationTroncon () {
    	modifTroncon.setCreation(true);
    	setNouveauPanel(modifTroncon);
    }
    public void afficherCreationVille () {
    	modifVille.setCreation(true);
    	setNouveauPanel(modifVille);
    }
    public void afficherModifRoute () {
    	modifRoute.setCreation(false);
    	setNouveauPanel(modifRoute);
    }
    public void afficherModifTroncon () {
    	modifTroncon.setCreation(false);
    	setNouveauPanel(modifTroncon);
    }
    public void afficherModifVille () {
    	modifVille.setCreation(false);
    	setNouveauPanel(modifVille);
    }
    public void afficherRechRoute () {
    	setNouveauPanel(rechRoute);
    }
    public void afficherRechTroncon () {
    	setNouveauPanel(rechTrocon);
    }
    public void afficherRechVille () {
    	setNouveauPanel(rechVille);
    }
    public void afficherRechAvRoute () {
    	setNouveauPanel(rechAvRoute);
    }
    public void afficherRechAvTroncon () {
    	setNouveauPanel(rechAvTroncon);
    }
    public void afficherRechAvVille () {
    	setNouveauPanel(rechAvVille);
    }
    public void afficherPanelPrecedent () {
    	setPanel (panelsPrecedents.pop());
    }
    
    protected void setNouveauPanel (PanelAdmin p) {
    	panelsPrecedents.push(panelCourant);
    	setPanel(p);
    }
    protected void setPanel (PanelAdmin p) {
    	panelCourant = p;
    	setContentPane(p);
    	p.initComponentValues();
    	setTitle(p.getTitle());
    	pack();
    }
}